! existing note structure
if tagexists is true

  #proceed="true"
  if @contents is validlink
	! Block duplicates in Media pane
	ifDef #objeList
	  if offset(@contents&"\1\"&#objeList)>0
	    #proceed="false"
	  else
	    #objeList&=" "&@contents
	  endif
	endif
  else
    #proceed="false"
  endif

  ! link to OBJE record
  if #proceed="true"
    #padding=3
	if @contents.FILE.FORM="url"
	  ifDef #numURLs[0]
        #numURLs[0]+=1
        #i=#numURLs[0]
        #numURLs[#i]=@contents
      else
        cell static,"Multimedia Link Invalid Here:"
        sizetofit
        cell Linkbutton
        text @contents.view
        offset -3
        RecordLink @contents
        sizetofit
        help "Click to see multimedia object or use Detach menu to remove the link"
      endif
	else
      #thumbW=int((#rightMargin$-#rightSkip-#leftSkip-(#mmPerRow-1)*#cellSkip)/#mmPerRow)
	  #thumbH=#thumbW/1.61
      cell LinkButton
	  set width #thumbW height #thumbH
      if #thumbW<2.5*#thumbnailSize$
        objectImage @contents
      else
        objectFull @contents
      endif
      #mmRatio=#imageHeight$/#imageWidth$
      #posWidth=#thumbW-2*#padding
      #posHeight=#thumbH-#padding-22
      #cellRatio=#posHeight/#posWidth
      if #mmRatio<#cellRatio
        if #posWidth<#imageWidth$
        	set imagewidth #posWidth
        endif
      else
        if #posHeight <#imageHeight$
          set imageheight #posHeight
        endif
      endif

	  ! comment section must wait to new version ID for formats
	  TextExpression @contents.rec
	  AppendedExpression view
	  autoreload yes
	  if @contents.FILE.TITL=""
	    text @contents.FILE
	  else
	    text @contents.FILE.TITL
	  endif

	  set imageposition above
      set border shadowlesssquare target child
      RecordLink @contents
      Help local("Click to view multimedia record")
    endif

    ! are there details
    hideexcess
  
  ! skipped duplicate images
  else if @contents is validlink
    hideexcess

  ! embedded multimedia
  else
    newline
    cell static,local("(Embedded multimedia - reopen file to fix)")
    set width -1 offset 3
    hideexcess
  endif

! no multimedia - create an attach button
else
  ! button to link to new or existing notes
  hskip 2
  cell CreateLinkButton
  set border shadowlesssquare width 26 height 26 target newifnew
  image "multimedia"
  help local("Click to attach multimedia object")
endif
